<?
	include "conexao.php" ;

	$bco ;
	$conec ;
	$conectou = 0 ;

	if (isset($_COOKIE["pedido"])) {

		$nrped = $_COOKIE["pedido"];
		$stgsql = $conec->prepare("select MAX(seq) from PEDIDOS where numero=:nrped");  
		$stgsql->execute(array(":nrped" => $nrped));

		$dados  = $stgsql->fetch();
		$seqped = $dados['MAX(seq)'] ;

		$seqped ++ ;

	} else {

		$stgsql = $conec->prepare("select * from ULTPEDIDO");  
		$stgsql->execute();
		$dados = $stgsql->fetch();

		$nrped = $dados['pedido'] ;
		$nrped++ ;

		$stgsql = $conec->prepare("update ULTPEDIDO set pedido = :nrped");  
		$stgsql->execute(array(":nrped" => $nrped));
		$res    = $stgsql->fetch() ;

		setcookie("pedido",$nrped) ;
		$seqped = 1 ;
	}

	$indpizza = $_COOKIE["pizzas"] ;
	$indaux = 0 ;

	while ($indaux <= $indpizza) 
	{
		$compo = "cb".$indaux ; 
		
		if (!empty($_POST["$compo"])) {
				
			$stgsql = $conec->prepare("insert into PEDIDOS values (:nrped,:seqped,:compo1)");  
			$stgsql->execute(array(":nrped" => $nrped, ":seqped" => $seqped, ":compo1" => $_POST["$compo"]));

			$res = $stgsql->fetch();
			$seqped++   ;

		}
		
		$indaux++ ;
	}
  
	echo "<META HTTP-EQUIV='REFRESH' CONTENT=\"0; URL='meupedido.php'\">" ;
  
?>